using UnityEngine;

public class PanZoom : MonoBehaviour
{
	private Vector3 touchStart;

	public float OrthoZoomOutMin = 1f;

	public float OrthoZoomOutMax = 8f;

	public float NonOrthoFovMin = 50f;

	public float NonOrthoFovMax = 70f;

	public Vector2 MinCamPos;

	public Vector2 MaxCamPos;

	public float XMultiply = 1f;

	public float YMultiply = 1f;

	public float ScrollMultiply = 1f;

	public float SnapMultiply = 0.01f;

	private Camera _camera;

	private void Awake()
	{
		_camera = Camera.main;
	}

	private void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			touchStart = Input.mousePosition;
		}
		if (Input.touchCount == 2)
		{
			Touch touch = Input.GetTouch(0);
			Touch touch2 = Input.GetTouch(1);
			Vector2 vector = touch.position - touch.deltaPosition;
			Vector2 vector2 = touch2.position - touch2.deltaPosition;
			float magnitude = (vector - vector2).magnitude;
			float num = (touch.position - touch2.position).magnitude - magnitude;
			zoom(num * Time.deltaTime * SnapMultiply);
		}
		else if (Input.GetMouseButton(0))
		{
			Vector2 vector3 = touchStart - Input.mousePosition;
			Vector3 position = _camera.transform.position + new Vector3(vector3.x * Time.deltaTime * XMultiply, 0f, vector3.y * Time.deltaTime * YMultiply);
			position.x = Mathf.Clamp(position.x, MinCamPos.x, MaxCamPos.x);
			position.z = Mathf.Clamp(position.z, MinCamPos.y, MaxCamPos.y);
			_camera.transform.position = position;
			touchStart = Input.mousePosition;
		}
		zoom(Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * ScrollMultiply);
	}

	private void zoom(float increment)
	{
		if (_camera.orthographic)
		{
			_camera.orthographicSize = Mathf.Clamp(_camera.orthographicSize - increment, OrthoZoomOutMin, OrthoZoomOutMax);
		}
		else
		{
			_camera.fieldOfView = Mathf.Clamp(_camera.fieldOfView - increment, NonOrthoFovMin, NonOrthoFovMax);
		}
	}
}
